<template>
  <t-modal
    title="审批"
    width="716px"
    :visible="visible"
    @ok="onSubmit()"
    @cancel="closeModal()"
    wrapClassName="approve-modal-container"
    forceRender
    v-bind:confirmLoading="confirmLoading"
  >
    <div class="curve-modal-body">
      <a-form-model ref="ruleForm" :model="form" :rules="rules">
        <a-form-model-item label="审批结果" prop="operate">
          <a-radio-group v-model="form.operate">
            <a-radio :value="2">通过</a-radio>
            <a-radio :value="3">不通过</a-radio>
          </a-radio-group>
        </a-form-model-item>
        <a-form-model-item label="审批意见">
          <a-input
            placeholder="请输入"
            type="textarea"
            :rows="4"
            v-model="form.reason"
          />
        </a-form-model-item>
      </a-form-model>
    </div>
  </t-modal>
</template>

<script>
import { approvePlanControl } from "@/api/progressManage";
export default {
  props: {
    visible: {
      type: Boolean,
      default: false,
    },
    versionInfo: {
      type: Object,
      default: () => {
        return {};
      },
    },
  },
  data() {
    return {
      form: {
        //结果
        operate: 2,
        //备注
        reason: "",
      },
      rules: {
        operate: [
          {
            required: true,
            message: "请选择审批结果",
          },
        ],
      },
      confirmLoading: false,
    };
  },
  methods: {
    onSubmit() {
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          let { form, versionId } = this;
          let formJson = {
            uuid: this.versionInfo.uuid,
            //结果
            operate: form.operate,
            //备注
            reason: form.reason,
          };
          this.confirmLoading = true;
          approvePlanControl(formJson)
            .then((res) => {
              if (res.statusCode === 200 || res === 1) {
                this.$message.success("审批成功", 1.5);
                this.closeModal();
                this.$$parent.getVersionData();
              } else {
                this.$message.error(res?.message ?? "审批失败");
              }
            })
            .catch(() => {
              this.$message.error("审批失败");
            })
            .finally((_) => {
              this.confirmLoading = false;
            });
        }
      });
    },
    //重置表单
    resetForm() {
      this.form = {
        //结果
        operate: 2,
        //备注
        reason: "",
      };
      this.$refs.ruleForm.resetFields();
    },
    //关闭弹窗
    closeModal() {
      this.resetForm();
      this.$emit("update:visible", false);
    },
  },
};
</script>

<style lang="less" scoped>
/deep/.approve-modal-container {
  .ant-modal-body {
    padding: 0 !important;
  }
  .curve-modal-body {
    padding: 20px 40px 20px 10px;
    max-height: 620px;
    overflow: auto;
    .ant-form-item {
      display: flex;
      .ant-form-item-label {
        flex-shrink: 0;
        width: 120px;
        label {
          color: #999999;
        }
      }
      .ant-form-item-control-wrapper {
        flex: 1;
      }
    }

    .sub-title {
      padding-left: 43px;
      font-family: Microsoft YaHei;
      font-weight: 400;
      font-size: 18px;
      color: #525a5d;
      position: relative;
      margin-bottom: 10px;
      display: flex;

      align-items: center;
      justify-content: space-between;
      &::after {
        content: "";
        width: 3px;
        height: 16px;
        background: #3759a0;
        position: absolute;
        left: 30px;
        top: 50%;
        transform: translateY(-50%);
      }
      .ant-btn {
        margin-right: 0;
      }
    }
  }
  .curve-modal-footer {
    display: flex;
    justify-content: center;
    padding: 20px 0;
    border-top: 1px solid #e8e8e8;
    button {
      &:last-child {
        margin-left: 20px;
      }
    }
  }
}
</style>
